package com.proxy.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DynamicProxyHandler implements InvocationHandler {

	private Object proxied;

	public DynamicProxyHandler(Object proxied) {
		this.proxied = proxied;
	}

	@Override
	//proxy:　　指代我们所代理的那个真实对象
	//method:　　指代的是我们所要调用真实对象的某个方法的Method对象
	//args:　　指代的是调用真实对象某个方法时接受的参数
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		System.out.println("********* proxy:" + proxy.getClass() + ". method:"
				+ method);
		if (args != null) {
			for (Object arg : args) {
				System.out.println(" " + args);
			}
		}
		return method.invoke(proxied, args);
	}

}
